package com.rightsidetech.http.controller.userApp.adverts;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.mall.service.MallUserAppCommodityService;
import com.rightsidetech.system.dtos.response.adverts.AppBannerResp;
import com.rightsidetech.system.entity.store.SysStoreInfo;
import com.rightsidetech.system.service.SysAdvertsBannerService;
import com.rightsidetech.system.service.SysStoreInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/userApp/banner")
@ShenyuSpringMvcClient(path = "/userApp/banner/**")
@Api(tags = "用户App banner相关")
public class AppBannerController {

    @Resource
    private SysAdvertsBannerService sysAdvertsBannerService;
    @Resource
    private SysStoreInfoService sysStoreInfoService;
    @Resource
    private MallUserAppCommodityService mallUserAppCommodityService;

    @GetMapping("/get")
    @ApiOperation("小程序获取banner")
    public ResponseData<List<AppBannerResp>> getList(Long storeId) {
        if(ObjectUtil.isEmpty(storeId)){
            return ResponseData.success(CollUtil.newArrayList());
        }
        SysStoreInfo store = sysStoreInfoService.selectByPrimaryKey(storeId);
        if(ObjectUtil.isEmpty(store)){
            return ResponseData.fail("未找到门店");
        }
        if(store.getStatus() == -1){
            return ResponseData.fail("当前门店未营业");
        }
        List<Long> commodityIds = mallUserAppCommodityService.selectCommodityIdsByAgentId(store.getSysAgentInfoId());
        return sysAdvertsBannerService.appBanner(commodityIds);
    }
}





